﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MVCCore.Models;
using NLog;

namespace MVCCore.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger = null;

        public static Logger nlog = LogManager.GetCurrentClassLogger();

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            _logger.LogInformation("[Test Log]Getting items.");
            return new string[] { "value1", "value2" };
        }



        public IActionResult Index()
        {
            nlog.Info("普通信息日志-----------");
            nlog.Debug("调试日志-----------");
            nlog.Error("错误日志-----------");
            nlog.Fatal("异常日志-----------");
            nlog.Warn("警告日志-----------");
            nlog.Trace("跟踪日志-----------");
            nlog.Log(NLog.LogLevel.Warn, "Log日志------------------");

            HttpContext.Session.SetString("SessionStartedTime", "Session started time:" + DateTime.Now.ToString());
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";


            ViewData["CurrentTime"] = "Current time:" + DateTime.Now.ToString();
            ViewData["SessionStartedTime"] = HttpContext.Session.GetString("SessionStartedTime");

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        public IActionResult ShowDetail()
        {
            return View();
        }
    }
}
